<template>
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false"
             v-dialogDrag>
      <div style="margin-left: 10px;">
          <el-form ref="form" :rules="rules" label-width="120px">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                     label-width="68px">
              <el-form-item label="工序名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入工序名称"
                          clearable @keyup.enter.native="handleQuery"/>
              </el-form-item>
              <el-form-item label="生产产品名称" prop="goodsName">
                <el-input v-model="queryParams.goodsName" placeholder="请输入生产产品名称"
                          clearable @keyup.enter.native="handleQuery"/>
              </el-form-item>
              <el-form-item label="生产产品型号" prop="goodsModel">
                <el-input v-model="queryParams.goodsModel" placeholder="请输入生产产品型号"
                          clearable @keyup.enter.native="handleQuery"/>
              </el-form-item>
              <el-form-item label="图纸号" prop="shuoming">
                <el-input v-model="queryParams.shuoming" placeholder="请输入图纸号"
                          clearable @keyup.enter.native="handleQuery"/>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addGongxu">添加工序</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="multiple"
                           @click="handleUpdateAll" v-hasPermi="['develop:LnGongxu:edit']">修改图纸号</el-button>
              </el-col>
            </el-row>
             <!--<el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading">-->
              <el-table border v-loading="loading" :data="columns" @selection-change="handleSelectionChange" ref="dragTable" >
                <el-table-column type="selection" width="55" align="center"/>
              <el-table-column label="排序" align="center" prop="idx"/>
              <el-table-column label="工序编号" align="center" prop="code"/>
              <el-table-column label="工序名称" align="center" prop="name"/>
              <el-table-column label="工时" align="center" prop="workHour"/>
              <el-table-column label="车间名称" align="center" prop="deptName"/>
              <el-table-column label="计件工资" align="center" prop="money"/>
              <el-table-column label="产品编码" align="center" prop="goodsCode"/>
              <el-table-column label="生产产品名称" align="center" prop="goodsName"/>
              <el-table-column label="生产产品型号" align="center" prop="goodsModel"/>
              <el-table-column label="关联设备" align="center" prop="photo"/>
              <el-table-column label="图纸号" align="center" prop="shuoming" show-overflow-tooltip/>
              <el-table-column sortable align="center" label="是否最后一道工序" prop="islast" >
                <template slot-scope="scope" >
                  <dict-tag :options="dict.type.yes_no" :value="scope.row.islast"/>
                </template>
              </el-table-column>
              <el-table-column label="工序文件" align="center" prop="file" width="200">
                <template slot-scope="scope">
                  <image-preview :src="scope.row.file" height="60px" width="40px"></image-preview>
                </template>
              </el-table-column>
              <!--<el-table-column label="序号" width="210">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.idx" :min="0" ></el-input-number>
                </template>
              </el-table-column>-->
              <!--<el-table-column align="center" label="工序图纸" prop="photo" width="200">
                <template slot-scope="scope">
                  <image-preview :src="scope.row.photo" height="60px" width="40px"></image-preview>
                </template>
              </el-table-column>-->
              <!--<el-table-column label="备注" align="center" prop="remark"/>-->
              <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="140">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-edit" @click="modifyIdx(scope.row)">修改排序及工资</el-button>
                  <el-popconfirm :title="`确认设为最后一道工序当前数据项？`" @confirm="setLast(scope.row)"
                                 style="margin-left: 10px;">
                    <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                               v-hasPermi="['develop:LnGongyigongxu:remove']">设为最后一道工序</el-button>
                  </el-popconfirm>
                  <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                 style="margin-left: 10px;">
                    <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                               v-hasPermi="['develop:LnGongyigongxu:remove']">删除</el-button>
                  </el-popconfirm>
                </template>
              </el-table-column>
            </el-table>
          </el-form>
      </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
    </div>
    <addGongxu-list ref="addGongxuList" @ok="getList"></addGongxu-list>
    <modifyIdx-form ref="modifyIdx" @ok="getList"></modifyIdx-form>
    <lnGongxuGongyi-form-all ref="formAll" @ok="getList"></lnGongxuGongyi-form-all>
  </el-dialog>
</template>

<script>
  import { getAction,addAction,deleteAction} from '@/api/manage'
  import AddGongxuList from '@/views/develop/lnGongyi/module/AddGongxuList'
  import LnGongxuGongyiFormAll from '@/views/develop/lnGongxu/module/LnGongxuGongyiFormAll'
  import ModifyIdxForm from '@/views/develop/lnGongyi/module/ModifyIdxForm'

  export default {
    name: "GongxulistForm",
    dicts: ['yes_no'],
    components: {
      AddGongxuList,
      ModifyIdxForm,
      LnGongxuGongyiFormAll,
    },
    data() {
      return {
        title: "关联工序",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        rules: {
        },
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        dataList: [],
        columns: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20000,
          gongyiId: null,
          gongxuId: null,
          code: null,
          name: null,
          goodsName: null,
          goodsModel: null,
          //orderByColumn: "idx",
          //isAsc: "asc",
          params: {},
        },
        url: {
          list:'/lnGongyigongxu/lnGongyigongxu/list',
          deleteByGyGx:'/lnGongyigongxu/lnGongyigongxu/deleteByGyGx',
          remove:'/lnGongyigongxu/lnGongyigongxu/',
          setLast:'/lnGongyigongxu/lnGongyigongxu/setLast',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      // this.intDictsForPrj();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight);
    },
    methods: {
      handleUpdateAll() {
        const ids =  this.ids;
        this.$refs.formAll.handleUpdate(ids);
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      addGongxu(){
        this.$refs.addGongxuList.showGx(this.queryParams.gongyiId);
      },
      modifyIdx(row){
        this.$refs.modifyIdx.show(row);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      setLast(row) {
        let params ={"id":row.id,"gongyiId":row.gongyiId}
        getAction(this.url.setLast, params).then(response => {
          this.$modal.msgSuccess("设定成功");
          this.getList();
        }).catch(() => {});
      },
      /*handleDelete(row){
        let params ={"gongxuId":row.id,"gongyiId":this.gongyiId}
        getAction(this.url.remove, params).then(response => {
          this.$modal.msgSuccess("删除成功");
          this.getList();
        }).catch(() => {});
      },*/
      shouGongxu(row){
        this.queryParams.gongyiId=row.id;
        this.open=true;
        this.getList();
      },
      /** 查询销售信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.columns = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
